package 算法.练习1;

import java.util.Arrays;

/**
 * @author:谢君臣
 * @Date:2021/7/27-19:33
 * @version:1.0
 * @function:
 */
public class NC22 {

    public static void main(String[] args) {
        merge(new int[]{1, 2, 3, 0, 0, 0}, 3, new int[]{2, 5, 6}, 3);
    }

    public static void merge(int A[], int m, int B[], int n) {
        int i = 0, j = 0;
        while (j < n) {
            if (A[i] > B[j] || i == m) {
                A = transForm(A, i, m);
                A[i] = B[j++];
                m++;
            }
            i++;
        }
        System.out.println(Arrays.toString(A));
    }

    private static int[] transForm(int[] a, int i, int m) {
        for (int j = m; j > i; j--)
            a[j] = a[j - 1];
        return a;
    }
}
